//
//  WPGetToken.m
//  ZhongChouPingTai
//
//  Created by WeiPan on 16/4/8.
//  Copyright © 2016年 WPJoe. All rights reserved.
//

#import "WPGetToken.h"
#import "AFNetworking.h"
#import "URL.h"

@implementation WPGetToken
+ (void)getTokenWithSuccessBlock:(void (^)(NSString *))success andWithFailureBlock:(void (^)(NSString *))failure {
    NSString * url = [BASIC_URL stringByAppendingString:@"moveSoftware/index.jhtml"];
    NSLog(@"%@", url);
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:url parameters:@{} success:^(AFHTTPRequestOperation * _Nonnull operation, id  _Nonnull responseObject) {
        if (responseObject) {
            if (responseObject[@"resultType"] && [responseObject[@"resultType"] intValue] && responseObject[@"resultMsg"]) {
                [[NSUserDefaults standardUserDefaults]setObject:responseObject[@"resultMsg"] forKey:@"token"];
                success(@"success");
                NSLog(@"已获取token");
            } else {
                failure(responseObject[@"resultMsg"] ? responseObject[@"resultMsg"]:@"网络数据错误");
            }
        } else {
            failure(responseObject[@"resultMsg"]?responseObject[@"resultMsg"]: @"网络数据错误");
        }
    } failure:^(AFHTTPRequestOperation * _Nonnull operation, NSError * _Nonnull error) {
        NSLog(@"%@", error.localizedDescription);
        failure(error.localizedDescription);
        NSLog(@"未能获取token");
    }];
    
}
@end
